package com.xxx.modules.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxx.modules.mapper.RecordMapper;
import com.xxx.modules.entity.Record;
import com.xxx.modules.service.RecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.Arrays;
import com.xxx.modules.utils.TimeUtil;

import javax.annotation.Resource;

/**
 * record
 *
 * @author 北易航
 * @since 1.0.0 2022-12-28
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements RecordService {

    @Resource
    private RecordMapper recordMapper;


    @Override
    public PageInfo<Record> selectRecordInfo(Record record, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<Record> wrapper = new QueryWrapper<>();
        if (record.getConnect() !=null){
            wrapper.like("connect",record.getConnect());
        }
        if (record.getCategory() !=null){
            wrapper.like("category",record.getCategory());
        }
        if (record.getReceive() !=null){
            wrapper.like("receive",record.getReceive());
        }
        if (record.getDescription() !=null){
            wrapper.like("description",record.getDescription());
        }
        List<Record> data = recordMapper.selectList(wrapper);
        return new PageInfo<>(data);
    }

    @Override
    public void saveRecordInfo(Record record) {
        record.setCreateTime(TimeUtil.getCurrentTime());
        recordMapper.insert(record);
    }

    @Override
    public void updateRecordInfo(Record record) {
        recordMapper.updateById(record);
    }

    @Override
    public void delRecordInfo(Integer id) {
        recordMapper.deleteById(id);
    }

    @Override
    public void delBatchRecordInfo(String idList) {
        List<String> list = Arrays.asList(idList.split(","));
        recordMapper.deleteBatchIds(list);
    }


}